declare @data char(10)
declare @dataf char(10)

select @data = '20020601'
select @dataf = '20020610'


update a set valor = valor from loja_venda_parcelas a join loja_venda b 
on b.codigo_filial = a.codigo_filial and b.terminal = a.terminal and b.lancamento_caixa = 
a.lancamento_caixa
where a.codigo_filial = '02' and b.data_venda between @data and @dataf

select
	filial,
	valor_venda = (select sum(valor_pago) from loja_venda a join filiais b on b.clifor = a.codigo_filial where 
			data_venda between @data and @dataf and filial = z.filial),
	valor_receber = (select sum(valor_original) from a_receber_cheques a where emissao between @data and @dataf  
			and filial = z.filial)
from filiais z where clifor = '02'

